/*
 * Copyright (c) 2008-2021 浩瀚深度 All Rights Reserved.
 *
 * <p>FileName: WebController.java</p>
 *
 * @author zz
 * @date 2024/2/20
 * @version 1.0
 * History:
 * v1.0.0 2024/2/20 Create
 */
package com.sqlweb.sqlweb.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;

/**
 * <p>Title: WebController</p>
 * <p>Description: </p>
 *
 * @author zz
 */

@RestController
public class WebController {

    @Value("${server.port}")
    private int port;

    @GetMapping("/apiServerUrl")
    public ResponseEntity<String> getApiServerUrl() {
        String hostAddress;
        try {
            hostAddress = InetAddress.getLocalHost().getHostAddress();
        } catch (Exception e) {
            hostAddress = "localhost";
        }
        return ResponseEntity.ok("http://" + hostAddress + ":" + port);
    }
}

